<template>
  <div>
    <!-- 资金返利对账表查询 -->
    <TopFilter :list="topFilterList" :cols="3" @filterChange="changeHandle" @onCollapse="collapseHandle" :labelWidth="110"></TopFilter>

    <Spin :spinning="exportLoading" tip="Loading...">
      <FilterTable
        ref="table"
        columnsRef="qjhRebateStatementApproval"
        :isSelectColumn="false"
        :columns="columns"
        :fetchapi="fetchApi"
        :params="fetchParams"
        :datakey="'records'"
        :onColumnsChange="columns => (this.columns = columns)"
      >
        <template slot="controls" slot-scope="props">
          <multiuse-button size="small" type="primary" :click="exportHandle">导 出</multiuse-button>
        </template>
      </FilterTable>
    </Spin>

    <Drawer :visible.sync="visible" :title="'明细'" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }" width="72%">
      <SonModel :rowData="formData" @close="emitCloseHandler" />
    </Drawer>
  </div>
</template>
<script>
import { dictionary } from '@/utils/dictMixin';
import { exportExcelFile } from '@/utils/index';
import { queryList, exportExcel ,exporturl} from '@/api/dealerFinance/RebateManage/RebateStatementQuery';
import SonModel from './SonModel';

export default {
  name: 'RebateStatementQuery',
  mixins: [dictionary],

  data() {
    this.BaseTable = null;
    return {
      topFilterList: this.createdFrom(),
      columns: this.createdTable(),
      fetchParams: {
        searchType: 1
      },
      fetchApi: queryList,
      formData: {},
      isDealer: false,
      visible: false,
      exportLoading: false
    };
  },
  components: {
    SonModel
  },
  mounted() {
    this.BaseTable = this.$refs.table.$refs.pageTable;
  },
  created() {},
  methods: {
    changeHandle(params) {
      this.fetchParams = Object.assign({}, this.fetchParams, params);
    },
    collapseHandle() {
      this.$nextTick(() => {
        this.BaseTable.EXECUTE_RESET_HEIGHT();
      });
    },

    seacherFun() {
      this.isDealer = true;
    },
    emitCloseHandler1(val, type) {
      this.isAdd = val;
      if (type == 'refresh') {
        this.fetchParams = Object.assign({}, this.fetchParams);
      }
    },
    emitCloseHandler(val, data) {
      this.isDealer = val;
      this.visible = val;
      if (data) {
        let dealerCodes = [];
        let dealerNames = [];
        data.map(x => {
          dealerCodes.push(x.dealerCode);
          dealerNames.push(x.dealerName);
        });
        this.topFilterList.find(x => x.fieldName == 'dealerCode').initialValue = dealerCodes.toString();
      }
    },
    detailHandle(row) {
      this.visible = true;
      this.formData = row;
    },
    // 导出
    async exportHandle() {
        let json = Object.assign({}, { CODE: 'CODE_00000242' }, this.fetchParams);
      let res = await exporturl(json);
      if (res.resultCode == 200) {
        this.$router.push('/admin/auth/oem/downloadCenter');
      }
      // await this.$confirm('是否将Excel表格保存至本地文件夹?', '提示', {
      //   confirmButtonText: '下载',
      //   cancelButtonText: '取消',
      //   type: 'warning'
      // })
      //   .then(() => {
      //     this.exportLoading = true;

      //     exportExcel(this.fetchParams)
      //       .then(response => {
      //         exportExcelFile(response.data, '资金返利对账表查询');
      //         this.exportLoading = false;
      //       })
      //       .catch(err => {
      //         console.log(err);
      //       });
      //   })
      //   .catch(() => {
      //     this.$message({
      //       type: 'info',
      //       message: '已取消'
      //     });
      //   });
    },
    createdFrom() {
      return [
        {
          type: 'SELECT',
          label: '对账分类',
          fieldName: 'verifyType',
          placeholder: '请选择',
          itemList: this.createDictList('6086')
        },
        {
          type: 'SELECT',
          label: '状态',
          fieldName: 'status',
          placeholder: '请选择',
          itemList: this.createDictList('6084').filter(x => x.value != 60841001)
        },
        {
          type: 'RANGE_DATE',
          label: '下发日期',
          fieldName: 'issueBeginDate|issueEndDate',
          initialValue: [],
          dateType: 'exactdaterange'
        },
        {
          type: 'SELECT',
          label: '动力形式',
          fieldName: 'powerType',
          placeholder: '请选择',
          itemList: this.createDictList('6008')
        }
      ];
    },
    createdTable() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          sorter: true,
          width: 80,
          fixed: 'left',
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '操作',
          dataIndex: 'column-action',
          fixed: 'left',
          render: (props, h) => {
            return (
              <div>
                <multiuse-button size="mini" type="text" onClick={() => this.detailHandle(props.row)}>
                  明细
                </multiuse-button>
              </div>
            );
          }
        },
        // {
        //   title: '事业部',
        //   dataIndex: 'deptName',
        //   sorter: true,
        //   filter: true,
        //   filterType: 'input'
        // },
        {
          title: '经销商代码',
          dataIndex: 'dealerCode',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '经销商名称',
          dataIndex: 'dealerName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '状态',
          dataIndex: 'status',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('6084').filter(x => x.value != 60841001),
          render: props => {
            return <span>{this.createDictText(props.row.status, '6084')}</span>;
          }
        },
        {
          title: '对账年月',
          dataIndex: 'accountVerifyDate',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '对账单名称',
          dataIndex: 'verifyName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '整车款余额',
          dataIndex: 'vehicleAccountAmount',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '整车返利余额',
          dataIndex: 'vehicleRebateAmount',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '备件款余额',
          dataIndex: 'partAccountAmount',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '备件返利余额',
          dataIndex: 'partRebateAmount',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '建店保证金余额',
          dataIndex: 'depositAmount',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '其他类应收款项',
          dataIndex: 'otherInAmount',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '其他类应付款项',
          dataIndex: 'otherOutAmount',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '生成日期',
          dataIndex: 'createdAt',
          sorter: true,
          filter: true,
          filterType: 'date-range',
          dateFormat: 'yyyy-MM-dd'
        },
        {
          title: '下发日期',
          dataIndex: 'issueDate',
          sorter: true,
          filter: true,
          filterType: 'date-range',
          dateFormat: 'yyyy-MM-dd'
        },
        {
          title: '反馈确认日期',
          dataIndex: 'confirmDate',
          sorter: true,
          filter: true,
          filterType: 'date-range',
          dateFormat: 'yyyy-MM-dd'
        },
        {
          title: '审批日期',
          dataIndex: 'checkDate',
          sorter: true,
          filter: true,
          filterType: 'date-range',
          dateFormat: 'yyyy-MM-dd'
        },
        {
          title: '对账结果',
          dataIndex: 'verifyResult',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('6085'),
          render: props => {
            return <span>{this.createDictText(props.row.verifyResult, '6085')}</span>;
          }
        }
      ];
    }
  }
};
</script>
